var express = require('express')
var router = express.Router()

let path = require('path')

var multer  = require('multer')




var storage = multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, "/public/images")
    },
    filename: function (req, file, cb) {
      // const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
      cb(null, Date.now() + path.extname(file.originalname))
    }
  })
  

var upload = multer({ storage: storage }).single("img")


  
router.post('/', upload, function(req,res){
    let file = req.file
    let imgUrl = '/images/' + file.filename
    res.json({
        code: 1,
        meg: '成功',
        date: imgUrl,

    })
})




  module.exports = router
